package com.xccwk.mybatisservlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xccwk.model.User;
import com.xccwk.serviceImp.MybatisMapperServiceImp;


@WebServlet("/mybathe")
public class MybatisServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		MybatisMapperServiceImp imp=new MybatisMapperServiceImp();
		System.out.println("hello");
		List<User> listUser;
		if(req.getParameter("id")!=null) {
			int id= Integer.parseInt(req.getParameter("id"));
			listUser=imp.findUserById(id);
			System.out.println(listUser.toString());
			req.getSession().setAttribute("listUser",listUser);
			req.getSession().setAttribute("flag", false);
		}else {
			listUser=imp.findAll();
			System.out.println(listUser.toString());
			req.getSession().setAttribute("listUser",listUser);
		}	
		resp.sendRedirect("login.jsp");
		
		
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

	
	
	
	
}
